/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __frmodule_show.c                                */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/18 by geyh                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"

#include "frstat_module.h"


static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

typedef struct __module_msg {
    unsigned long ul_requests;
    unsigned long ul_responses;
    unsigned long ul_fails;
    unsigned long ul_succs;
} module_msg;

typedef struct __module_msg_avg {
    unsigned long ul_requests[4];
    unsigned long ul_responses[4];
    unsigned long ul_fails[4];
    unsigned long ul_succs[4];
} module_msg_avg;

typedef struct __module_stat {
    char *p_module_name;
    u_short us_proto;
    int     i_l7_proto;
    struct timeval start_time; //模块开始时间

    module_msg st_stat_total;
    module_msg_avg st_stat_avg;

} module_stat;

void __frmodule_show(Frlist_node* p_node, char *p_outbuff, unsigned int ui_outlen);

static void __case1(void)
{
    Frlist_node* p_node = NULL;
    char *p_outbuff = NULL;
    unsigned int ui_outlen = 1024;
    module_stat *p_st_list_stat = NULL;

    p_st_list_stat = (module_stat *)frmalloc(sizeof(module_stat));
    memset(p_st_list_stat, 0x00, sizeof(module_stat));

    p_st_list_stat->st_stat_total.ul_requests = 10;
    p_st_list_stat->st_stat_total.ul_responses = 10;
    p_st_list_stat->st_stat_total.ul_succs = 10;
    p_st_list_stat->st_stat_total.ul_fails = 10;

    p_node = frlist_node_create(p_st_list_stat);

    p_outbuff = (char *)frmalloc(ui_outlen);
    __frmodule_show(p_node,p_outbuff,ui_outlen);
    frdbg("\t%s\n",p_outbuff);
    CU_ASSERT_STRING_EQUAL(p_outbuff,"module_name=(null), proto=unknown(0), l7=0, load_time=1970/01/01 08:00:00, status=USE_MODULE\n\trequests=10(0/s), responses=10(0/s), fails=10(0/s), succs=10(0/s)\n")

    frfree(p_outbuff);
    frfree(p_node->data);
    frfree(p_node);
    return;
}




int add_suite___frmodule_show(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frstat_module __frmodule_show()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
//    CU_add_test(pSuite, "case2", __case2);
//    CU_add_test(pSuite, "case3", __case3);
//    CU_add_test(pSuite, "case4", __case4);

    return FR_SUCC;
}
